package meiRiYiTi;

/**
 * Author: 笨蛋超人不会飞
 * Date:  9:31
 */
public class day_2391 {
    public int garbageCollection(String[] garbage, int[] travel) {
        int tra_m=0;
        int tra_g=0;
        int tra_p=0;
        int tra=0;
        int result=0;
        result+=garbage[0].length();
        for (int i =1 ; i < garbage.length; i++) {
//           先转化为数组
            int sum=0;
            tra+=travel[i-1];
            char[] arr = garbage[i].toCharArray();
            result+=garbage[i].length();
            int sum_m=0;
            int sum_g=0;
            int sum_p=0;
            for (int j = 0; j < arr.length; j++) {
                if (sum_m == 1 && sum_g == 1 && sum_p == 1) {
//                    说明不用找了，直接break
                    break;
                }
                if (arr[j] == 'M') {
                    sum_m = 1;
                    tra_m = tra;
                }
                if (arr[j] == 'G') {
                    sum_g = 1;
                    tra_g = tra;
                }
                if (arr[j] == 'P') {
                    sum_p = 1;
                    tra_p = tra;
                }

            }

        }
        return  result+tra_m+tra_g+tra_p;
    }
}
